

package com.hazelcast.internal.util.phonehome;

import com.hazelcast.config.ConfigAccessor;
import com.hazelcast.config.UserCodeNamespacesConfig;
import com.hazelcast.instance.impl.Node;

import static com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.UCN_ENABLED;
import static com.hazelcast.internal.util.phonehome.PhoneHomeMetrics.UCN_NAMESPACE_COUNT;

class UserCodeNamespacesMetricsProvider implements MetricsProvider {

    @Override
    public void provideMetrics(Node node, MetricsCollectionContext context) {
        UserCodeNamespacesConfig nsConfigs = node.getConfig().getNamespacesConfig();
        boolean enabled = nsConfigs.isEnabled();
        context.collect(UCN_ENABLED, enabled);
        if (enabled) {
            context.collect(UCN_NAMESPACE_COUNT, ConfigAccessor.getNamespaceConfigs(nsConfigs).size());
        }
    }
}
